
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
		<title>XXX平台商家端</title>
		<!--内容样式-->
		<link rel="stylesheet" href="/Public/Home/supplier/css/style.css" />
		<script src="/Public/static/jquery-2.0.3.min.js"></script>
		<script src="/Public/static/layer/layer.js"></script>
		<script src="/Public/static/jPages.js"></script>
		<!--内容样式-->
		<link rel="stylesheet" href="__PUBLIC__/Home/css/page.css" />
		<style>
		    .holder a{border:1px solid #e1e1e1;color:#909090;cursor:pointer;}
		    .jp-current{padding:6px 6px;border:1px solid #e1e1e1;background:#f55555;cursor:pointer;}
		    .holder .jp-current{color:#fff;cursor:pointer;}
		    .page{margin: 0 0 0 0}
			.upload-file {
				border: 1px solid #ccc;
				width: 100px;
				height: 100px;
				object-fit: cover;
			}

			.upload-files-div {
				position: relative;
				display: block;
				width: 100px;
				height: 100px;
				border: 1px solid #ddd;
				float: left;
				margin-right: 10px;
				cursor: pointer;
			}

			.upload-files {
				border: 1px solid #ccc;
				margin-right: 10px;
				width: 100px;
				height: 100px;
				object-fit: cover;
				float: left;
			}

			.upload-file-del {
				position: absolute;
				left: 0;
				bottom: -1px;
				display: inline-block;
				width: 101px;
				height: 20px;
				line-height: 20px;
				text-align: center;
				background: rgba(0, 0, 0, 0.8);
				opacity: 0.6;
				z-index: 10;
				color: #fff;
			}

			



			/* 以下为新增内容的样式 */
			.content .ct-release .ctr-box .ctrb-fl .ctrbf-zd {
				margin-left: 50px;
				width: 150px;
			}
			.control-group {
				padding-left: 200px;
			}
			.controls {
				margin-top: 25px;
				margin-bottom: 25px;
				margin-left: 200px;
				float: left;
				font-size: 14px;
			}
			.controls .cTitle{
				margin-top: 25px;
				margin-bottom: 25px;
				
				font-size: 14px;
			}
			
			/* 第二次增加 */
			.control-group .controls1 .btn{
				    width: 240px;
					height: 50px;
					background-color: #fff;
					border: none;
					border: 1px #eee solid;
					text-align: left;
					padding-left: 15px;
				
			}
			.control-group .controls1 input ,
			.control-group .controls1 .btn 
			{
					padding: 0 10px;
					width:120px;
					height:50px;
					border:#ddd 1px solid;
					margin-right:5px;

			}
			.control-group .control-label{
					font-size: 14px;
				    line-height: 50px;
				    color: #333;
			}
			#lv_table_con{
				padding-left: 0px;
				margin-left: 200px;
				border: 1px #ddd solid;
				margin-top:30px;
				display: -web-flex;
				display: flex;
				flex-direction: column;
				align-items: center;
			}
			#cc{
				width: 50px;
				height: 50px; 
				border: 1px #ddd solid;
			}
			

			/*弹出框*/
			.tck-demo{
				display: none;
				width: 100%;
				height: 100%;
				background: rgba(0,0,0,0.3);
				position: fixed;
				top: 0;
				left: 0;
				z-index: 800;
			}

			.tck-demo .tk-box{
				display: block;
				width: 1000px;
				height: 600px;
				background: #fff;
				border-radius: 10px;
				box-shadow: 0 0 6px #aaaaaa;
				position: fixed;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 1000;
				margin: auto;
			}

			.tck-demo .tk-box .tkb-title{
				display: block;
				width: calc(100% - 40px);
				height: 70px;
				padding: 0 20px;
				background: #6a86c5;
				border-top-left-radius: 10px;
				border-top-right-radius: 10px;
			}

			.tck-demo .tk-box .tkb-title .tkbt-bt{
				display: block;
				width: auto;
				font-size: 16px;
				line-height: 70px;
				color: #fff;
				font-weight: bold;
				float: left;
			}

			.tck-demo .tk-box .tkb-title .tkbt-close{
				display: block;
				width: 36px;
				height: 36px;
				float: right;
				margin: 17px 0;
				cursor: pointer;
			}

			.tck-demo .tk-box .tkb-title .tkbt-close img{
				display: block;
				width: 100%;
				height: 100%;
			}

			.tck-demo .tk-box .tkb-table{
				width: 100%;
				border-collapse:collapse;  
				border-spacing:0;
			}
			.tck-demo .tk-box .tkb-table tr{
				width: 100%;
			}
			.tck-demo .tk-box .tkb-table th{
				height: 60px;
				padding: 0 20px;
				font-size: 14px;
				line-height: 16px;
				color: #333;
				text-align: left;
				background: #f5f5f5;
				font-weight: bold;
				border-bottom: 1px solid #eee;
			}
			.tck-demo .tk-box .tkb-table td{
				border-bottom: 1px solid #eee;
				height: 60px;
				padding: 0 20px;
				font-size: 14px;
				line-height: 18px;
				color: #666;
				text-align: left;
			}

			.tck-demo .tk-box .tkb-table td a{
				text-decoration: underline;
				color: #2a6bff;
				cursor: pointer;
			}

			.tck-demo .tk-box .tkb-table td .tkbt-img{
				display: block;
				width: 140px;
				height: 80px;
				float: left;
				margin: 10px 0;
			}

			.tck-demo .tk-box .tkb-table td .tkbt-img img{
				display: block;
				width: 100%;
				height: 100%;
				object-fit: cover;
			}

			.tck-demo .tk-box .tkb-table td .tkbt-wz{
				display: flex;
				width: calc(100% - 170px);
				height: 80px;
				font-size: 14px;
				line-height: 18px;
				color: #333;
				text-align: justify;
				float: left;
				margin: 10px 0 0 10px;
				align-items: center;
			}

			.tck-demo .tk-box .tkb-btn{
				display: block;
				width: calc(100% - 40px);
				padding: 0 20px;
				margin: 20px auto 0 auto;
			}
			.tck-demo .tk-box .tkb-btn .tkbb-an{
				display: block;
				width: 38px;
				height: 38px;
				background: #fff;
				border-radius: 10px;
				border: 1px solid #e5e5e5;
				font-size: 14px;
				line-height: 38px;
				color: #666;
				text-align: center;
				float: left;
				margin-right: 6px;
				cursor: pointer;
			}
			.tck-demo .tk-box .tkb-btn .tkbb-an:hover{
				background: #6a86c5;
				color: #fff;
			}
			.tck-demo .tk-box .tkb-btn .tkbb-an-on{
				background: #6a86c5;
				color: #fff;
			}


			.tck-demo .tk-box .tkb-fpxs{
				display: block;
				width: 100%;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-top{
				display: block;
				width: calc(100% - 40px);
				height: 70px;
				padding: 0 20px;
				background: #f5f5f5;
				border-bottom: 1px solid #eee;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-top .tkbft-wb{
				display: block;
				width: calc(830px - 42px);
				height: 48px;
				padding: 0 20px;
				background: #fff;
				border: 1px solid #e5e5e5;
				font-size: 14px;
				line-height: 14px;
				color: #333;
				float: left;
				margin: 10px 0;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-top .tkbft-wb2{
				display: block;
				width: 204px;
				height: 48px;
				padding: 0 12px;
				background: #fff;
				border: 1px solid #e5e5e5;
				font-size: 14px;
				line-height: 14px;
				color: #333;
				float: left;
				margin: 10px 0;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-top .tkbft-xl{
				display: block;
				width: 190px;
				height: 50px;
				padding: 0 12px;
				background: #fff;
				border: 1px solid #e5e5e5;
				font-size: 14px;
				line-height: 14px;
				color: #333;
				float: left;
				margin: 10px 10px 10px 0;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-top .tkbft-ss{
				display: block;
				width: 120px;
				height: 50px;
				background: #2a6bff;
				border: none;
				border-radius: none;
				font-size: 14px;
				line-height: 50px;
				color: #fff;
				text-align: center;
				padding: 0;
				float: left;
				margin: 10px 0 10px 10px;
				cursor: pointer;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-nr{
				display: block;
				width: 100%;
				height: 350px;
				padding: 10px 0;
				overflow-y: scroll;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-nr .tkbfn-box{
				display: block;
				width: 468px;
				height: 48px;
				background: #fff;
				border: 1px solid #e5e5e5;
				float: left;
				margin: 10px 0 10px 20px;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-nr .tkbfn-box span{
				display: block;
				width: auto;
				font-size: 14px;
				line-height: 48px;
				color: #333;
				float: left;
				margin-left: 20px;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-nr .tkbfn-box input{
				display: block;
				width: 18px;
				height: 18px;
				float: right;
				margin: 15px 20px 15px 0;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-nr .tkbfn-box .tkbfnb-yc{
				display: block;
				width: 20px;
				height: 22px;
				float: right;
				margin: 13px 12px 13px 0;
				cursor: pointer;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-nr .tkbfn-box .tkbfnb-yc img{
				display: block;
				width: 100%;
				height: 100%;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-img{
				display: block;
				width: 100%;
				height: 360px;
				padding-top: 10px;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-img .tkbfi-box{
				display: block;
				width: 225px;
				float: left;
				margin: 10px 0 10px 20px;
				position: relative;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-img .tkbfi-box .tkbfib-pic{
				display: block;
				width: calc(100% - 2px);
				height: 118px;
				border: 1px solid #e5e5e5;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-img .tkbfi-box .tkbfib-pic img{
				display: block;
				width: 100%;
				height: 100%;
				object-fit: cover;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-img .tkbfi-box .tkbfib-bt{
				display: block;
				width: 100%;
				font-size: 14px;
				line-height: 14px;
				color: #333;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				margin-top: 10px;
			}

			.tck-demo .tk-box .tkb-fpxs .tkbf-img .tkbfi-box .tkbfib-an{
				display: block;
				width: 20px;
				height: 20px;
				margin: 0;
				position: absolute;
				top: 10px;
				right: 10px;
				z-index: 100;
			}



			.tck-demo .tk-box .tkb-zdfp{
				display: block;
				width: calc(100% - 40px);
				padding: 10px 20px 0 20px;
			}

			.tck-demo .tk-box .tkb-zdfp .tkbz-box{
				display: block;
				width: calc(100% - 26px);
				height: 48px;
				background: #fff;
				border: 1px solid #e5e5e5;
				padding: 0 12px;
				margin-top: 10px;
				position: relative;
			}

			.tck-demo .tk-box .tkb-zdfp .tkbz-box .tkbzb-l{
				display: block;
				width: 300px;
				height: 48px;
				border: 0;
				background: none;
				padding: 0;
				font-size: 14px;
				line-height: 14px;
				color: #333;
				float: left;
			}

			.tck-demo .tk-box .tkb-zdfp .tkbz-box .tkbzb-r{
				display: block;
				width: auto;
				font-size: 14px;
				line-height: 48px;
				color: #333;
				position: absolute;
				top: 0;
				right: 12px;
				z-index: 100;
			}

			.tck-demo .tk-box .tkb-zdfp .tkbz-box select{
				display: block;
				width: 100%;
				height: 48px;
				background: none;
				border: none;
				padding: 0;
				font-size: 14px;
				line-height: 20px;
				color: #333;
			}

			.tck-demo .tk-box .tkb-zdfp .tkbz-bt{
				display: block;
				width: 100%;
				font-size: 14px;
				line-height: 14px;
				color: #333;
				padding-top: 14px;
			}

			.tck-demo .tk-box .tkb-sqzy{
				display: block;
				width: calc(100% - 40px);
				padding: 20px 20px 0 20px;
				height: 170px;
			}

			.tck-demo .tk-box .tkb-sqzy h3{
				display: block;
				width: 100%;
				font-size: 16px;
				line-height: 16px;
				color: #333;
				font-weight: bold;
			}

			.tck-demo .tk-box .tkb-sqzy p{
				display: block;
				width: 100%;
				font-size: 14px;
				line-height: 24px;
				color: #777;
				text-align: justify;
				margin-top: 12px;
			}

			.tck-demo .tk-box .tkb-sqzy h4{
				display: block;
				width: 100%;
				font-size: 16px;
				line-height: 28px;
				color: #333;
				text-align: center;
				margin: 60px auto 0 auto;
			}


			.tck-demo .tk-box .tkb-qr{
				display: block;
				width: 120px;
				height: 50px;
				background: #2a6bff;
				border-radius: 6px;
				font-size: 14px;
				line-height: 50px;
				color: #fff;
				text-align: center;
				margin-top: 20px;
				margin-left: calc(100% - 140px);
				cursor: pointer;
			}

			/* 商品单项样式*/
			.ctxb-sp{
				margin-left: 200px
			}
			 .xbnt-kc{
				display: block;
				width: 500px;
				height: 120px;
				background: #fafafa;
				border: 1px solid #e5e5e5;
				padding: 10px 10px;
				margin: 0 20px 20px 0px;
				position: relative;
				float: left;
			}

		 .xbnt-kc .xbntk-img{
				display: block;
				width: 200px;
				height: 120px;
				float: left;
			}

			 .xbnt-kc .xbntk-img img{
				display: block;
				width: 100%;
				height: 100%;
				object-fit: cover;
			}

			 .xbnt-kc .xbntk-wz{
				display: block;
				width: 260px;
				height: 120px;
				float: left;
				margin-left: 20px;
			}

			 .xbnt-kc .xbntk-wz h3{
				display: block;
				width: 100%;
				font-size: 16px;
				line-height: 16px;
				color: #333;
				margin-top: 10px;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			 .xbnt-kc .xbntk-wz h4{
				display: block;
				width: 100%;
				font-size: 14px;
				line-height: 14px;
				color: #2a6bff;
				font-weight: normal;
				margin-top: 20px;
			}

			 .xbnt-kc .xbntk-wz span{
				display: block;
				width: 100%;
				font-size: 14px;
				line-height: 14px;
				color: #ff2d2d;
				margin-top: 30px;
			}

			 .xbnt-kc .xbntk-sc{
				display: block;
				width: 40px;
				height: 40px;
				position: absolute;
				top: 0;
				right: 0;
				z-index: 100;
				cursor: pointer;
			}

			 .xbnt-kc .xbntk-sc img{
				display: block;
				width: 100%;
				height: 100%;
			}

						
		</style>
	</head>
	<body>
		<div class="main">
			<include file="head" />
			<!--  左侧导航  -->
			<div class="nav">
				<div class="na-title">
					<img src="/Public/Home/supplier/images/icon_ml.png" />
					<div class="nat-mc">目录</div>
					<div class="divclear"></div>
				</div>
				<div class="na-box">
					<a href="/index.php?s=/Home/Supplier/book_index.html" class="nab-btn cur"
						>书籍列表
					</a>

<!-- 					<a href="/index.php?s=/Home/Supplier/book_spec.html" class="nab-btn">书籍规格
					</a> -->
				</div>
			</div>
			<!--  右侧内容  -->
			<div class="content">
				<div class="ct-title">
					<div class="ctt-bt">发布书籍</div>
				</div>
				<div class="ct-release">

					<!--基本信息-->
					<div class="ctr-box">
						<div class="ctrb-title">

							<h3>基本信息</h3>
							<div class="divclear"></div>
						</div>
						<div class="ctrb-xx">
							<div class="ctrbx-zd">书籍类型：</div>
							<label>
								<input type="radio" name="type" value="1">
								<span>单个书籍</span>
								<div class="divclear"></div>
							</label>
							<label>
								<input type="radio" name="type" value="2" onclick="showCourse()">
								<span>套餐(选择多个书籍进行组合)</span>
								<div class="divclear"></div>
							</label>
							<div class="divclear"></div>
						</div>
						<div class="ctxb-sp">


							<div class="divclear"></div>
						</div>
						<div class="divclear"></div>
						<div class="ctrb-xx">
							<div class="ctrbx-zd">书籍名称<span class="important">*</span></div>
							<input type="text" placeholder="请输入书籍名称" name="name">
							<div class="divclear"></div>
						</div>

						<div class="ctrb-xx">
							<div class="ctrbx-zd">出版社：</div>
							<input type="text" name="press">
							<div class="divclear"></div>
						</div>
						<div class="ctrb-xx">
							<div class="ctrbx-zd">作者：</div>
							<input type="text" name="author">
							<div class="divclear"></div>
						</div>
						<div class="ctrb-xx">
							<div class="ctrbx-zd">出版时间：</div>
							<input type="text" name="publication_time">
							<div class="divclear"></div>
						</div>


						<div class="ctrb-fl">
							<div class="ctrbf-zd">商品分类：</div>
							<select name="type1" onchange="de()" id="pr">
									<option value="">选择一级分类</option>
								<volist name="type_list" id="item">
									<option value="{$item.id}" <if condition="$msg['type1'] eq $item['id']">selected</if>>{$item.name}</option>
								</volist>
							</select>
							<select name="type2" id="ar">
								<option value="">选择二级分类</option>
							</select>
							<div class="divclear"></div>
						</div>
						<div class="control-group">
							<label class="control-label"> </label>
							<div class="controls1">
								<button id="add_lv1" class="btn btn-primary" type="button">添加规格项</button>
								<button id="update_table" class="btn btn-success" type="button">生成规格项目表</button>
							</div>
						</div>
						<div id="lv_table_con" class="control-group" style="display: none;">
							<label class="control-label">规格项目表</label>
							<div class="controls1">
								<div id="lv_table">

								</div>
							</div>

						</div>





						<!-- 						<div class="ctrb-fmt">
							<div class="ctrbx-zd">书籍banner图片<span class="important">*</span></div>
							<div class="ctrbf-img">
								<img src="/Public/Home/supplier/images/img_sctp.png" />
							</div>
							<div class="divclear"></div>
							<div class="ctrbf-ts">建议750px*750px 支持5张 2MB以下</div>
							<div class="divclear"></div>
						</div> -->
						<div class="controls" style="width:100%;margin-bottom:10px">
							<div calss="cTitle">轮播图</div>
							<input type="file" id="imgs_file" multiple style="display: none">
							<input type="hidden" name="imgs" id="imgs" />
							<div class="imgs_div">
															</div>
							<img class="upload-files" id="uploadImgs"
								src="/Public/Home/supplier/images/img_sctp.png">

						</div>
						<div class="ctrb-xq">
							<div class="ctrbx-zd">书籍详情：</div>
							<div class="ctrbx-fwb">
								<textarea style=" margin-left:12px;" id="content" name="detail"></textarea>
										<input type="hidden" name="parse" value="0">
		<link rel="stylesheet" href="/Public/static/kindeditor/default/default.css" />
			<script charset="utf-8" src="/Public/static/kindeditor/kindeditor-min.js"></script>
			<script charset="utf-8" src="/Public/static/kindeditor/zh_CN.js"></script>
			<script type="text/javascript">
				var editor_detail;
				KindEditor.ready(function(K) {
					editor_detail = K.create('textarea[name="detail"]', {
						allowFileManager : false,
						themesPath: K.basePath,
						width: '100%',
						height: '300px',
						resizeType: 1,
						pasteType : 2,
						urlType : 'absolute',
						fileManagerJson : '/index.php?s=/Home/Supplier/fileManagerJson.html',
						//uploadJson : '/index.php?s=/Home/Supplier/uploadJson.html' }
						uploadJson : '/index.php?s=/Home/Addons/execute/_addons/Editor/_controller/Upload/_action/ke_upimg.html'
					});
				});

				$(function(){
					$('textarea[name="detail"]').closest('form').submit(function(){
						editor_detail.sync();
					});
				})
			</script>

									</div>
							<div class="divclear"></div>
						</div>
					</div>

					<input type="hidden" id="iid" value="{$iid}">
					<input type="hidden" name="gg">
					<!--按钮-->
					<div class="ctr-btn">
						<div class="ctrb-l" id="save_product">保存</div>

					</div>

				</div>
			</div>
		</div>


		</div>


						<!-- 选择课程 弹出框-->
	<div class="tck-demo" id="tck-xzkc">
		
		<div class="tk-box">
			<div class="tkb-title">
				<div class="tkbt-bt">选择书籍</div>
				<div class="tkbt-close" onClick="document.getElementById('tck-xzkc').style.display='none'">
					<img src="__PUBLIC__/Home/images/icon_delete.png" />
				</div>
				<div class="divclear"></div>
			</div>
			<div class="tkb-fpxs">
				<div class="tkbf-top">
					<select class="tkbft-xl yi" onchange="dem()" name="one_type_id" id="one">
						<volist name="parent" id="item">
							<option value="{$item['id']}">{$item['name']}</option>
						</volist>
					</select>
					<select class="tkbft-xl er" name="two_type_id" id="two">
						<volist name="child" id="item">
							<option value="{$item['id']}">{$item['name']}</option>
						</volist>
					</select>
					<input type="text" class="tkbft-wb2" id="namm" placeholder="输入课程名称搜索" name="name">
					<button class="tkbft-ss" id="sub">搜索</button>
					<div class="divclear"></div>
				</div>
				<div class="tkbf-img" id="itemContainer">
					<volist name="course" id="item">
						<div class="tkbfi-box">
							<div class="tkbfib-pic">
								<img src="{$item.img}" />
							</div>
							<div class="tkbfib-bt">{$item.name}</div>
							<input type="checkbox" class="tkbfib-an" name="course" value="{$item.id}">
						</div>
					</volist>
					<div class="divclear"></div>
				</div>
			</div>
			<div class="tkb-btn" style="width: auto;padding: 0;float: left;margin: 20px 0 0 20px;">
	            <div class="page">
	                <div class="holder" style="font-size:12px;"></div>
	            </div>
	        </div>
			<div class="tkb-qr qd" style="float: right;margin: 15px 20px 0 0;">确定选择</div>
			<div class="divclear"></div>
		</div>
		
	</div>
		

	</body>
</html>

<script type="text/javascript">
	var lv1HTML = '<div class="control-group lv1 item-attr">' +
		'<label class="control-label">规格名称</label>' +
		'<div class="controls1">' +
		'<input type="text" name="lv1" placeholder="规格名称">' +
		'<button class="btn btn-primary add_lv2" type="button">添加参数</button>' +
		'<button class="btn btn-danger remove_lv1" type="button">删除规格</button>' +
		'</div>' +
		'<div class="controls1 lv2s"></div>' +
		'</div>';

	var lv2HTML = '<div style="margin-top: 5px;">' +
		'<input type="text" name="lv2" placeholder="参数名称">' +
		'<button class="btn btn-danger remove_lv2" type="button">删除参数</button>' +
		'</div>';

	$(document).ready(function() {
		$('#add_lv1').on('click', function() {
			var last = $('.control-group.lv1:last');
			if (!last || last.length == 0) {
				$(this).parents('.control-group').eq(0).after(lv1HTML);
			} else {
				last.after(lv1HTML);
			}
		});

		$(document).on('click', '.remove_lv1', function() {
			$(this).parents('.lv1').remove();
		});

		$(document).on('click', '.add_lv2', function() {
			$(this).parents('.lv1').find('.lv2s').append(lv2HTML);
		});

		$(document).on('click', '.remove_lv2', function() {
			$(this).parent().remove();
		});
		$(document).on('click', '#save_product', function() {
			var hy=$("input[name='gg']").val();
			if(hy !== '1'){
				alert('规格不能为空');return false;
			}

			var obj = {};
			var i = 0;
			var first = '';
			var tmp = {};
			var chk_value = [];
			$("#lv_table input[type='text']").each(function(index, e) {
				var iid = $('#iid').val();
				var name = $(e).attr('name');
				var value = $(e).val();
				//console.log(value);
				symbol = name.split('|')[0];
				key = name.split('|')[1];
				if (index == 0) {
					first = symbol;
					tmp = {
						symbol: symbol,
						item_id: iid
					};
				} else if (first != symbol) {
					first = symbol;
					i++;
					tmp = {
						symbol: symbol,
						item_id: iid
					};
				}
				tmp[key] = value;
				obj[i] = tmp;
			});
			// $("#lv_table img").each(function (index, e) {
			// 	chk_value.push(bb);
			// }
			var ll = $("#lv_table img");

			for (var ii = 0; ii < ll.length; ii++) {
				var jj = ll.eq(ii).attr('data-id');
				if (jj == undefined) {
					jj = 0;
				}
				chk_value.push(jj);

			}
			// console.log(chk_value);return false;
			var iid = $('#iid').val();
			var one_type_id = $("#pr  option:selected").val();
			var two_type_id = $("#ar  option:selected").val();
			var name = $("input[name='name']").val();
			var press = $("input[name='press']").val();
			var type = $("input[name='type']:checked").val();
			var author = $("input[name='author']").val();
			var publication_time = $("input[name='publication_time']").val();
			var detail = $('.ke-edit-iframe').contents().find('html body').html();
			var imgs = $("input[name='imgs']").val();
			var good_id=[];
			$("input[name='good_id[]']").each(function(index, e) {
				var gdd=$(e).val();
				good_id.push(gdd);
			});
			$.ajax({
				url: "/index.php?s=/Home/Supplier/save_sku.html",
				data: {
					one_type_id: one_type_id,
					two_type_id: two_type_id,
					name: name,
					press:press,
					type: type,
					author: author,
					publication_time: publication_time,
					detail: detail,
					obj: obj,
					iid: iid,
					chk_value: chk_value,
					imgs:imgs,
					good_id:good_id
				},
				dataType: 'json',
				type: 'post',
				'success': function(e) {
					if (e.code == 100) {
						alert('新增成功');
						var url = "/index.php?s=/Home/Supplier/book_index.html";
						location.href = url;
					} else {
						alert('新增失败');
						var url = "/index.php?s=/Home/Supplier/book_index.html";
						location.href = url;
					}
				}
			});
			//console.log(obj);return false;
		});


		$(document).on('click', '#save_attr', function() {
			save_attr();
		});
		$('#update_table').on('click', function() {
			$("input[name='gg']").val(1);
			save_attr();
			update_table();
		});

		function update_table() {
			var lv1Arr = $('input[name="lv1"]');
			if (!lv1Arr || lv1Arr.length == 0) {
				$('#lv_table_con').hide();
				$('#lv_table').html('');
				return;
			}
			for (var i = 0; i < lv1Arr.length; i++) {
				var lv2Arr = $(lv1Arr[i]).parents('.lv1').find('input[name="lv2"]');
				if (!lv2Arr || lv2Arr.length == 0) {
					alert('请先删除无参数的规格项！');
					return;
				}
			}

			var tableHTML = '';
			tableHTML += '<table class="table table-bordered">';
			tableHTML += '    <thead>';
			tableHTML += '        <tr>';
			for (var i = 0; i < lv1Arr.length; i++) {
				tableHTML += '<th width="50">' + $(lv1Arr[i]).val() + '</th>';
			}
			// tableHTML += '            <th width="20">售价</th>';
			tableHTML += '            <th width="20">成本价</th>';
			tableHTML += '            <th width="20">编码</th>';
			tableHTML += '            <th width="20">库存</th>';
			tableHTML += '            <th width="20">图片</th>';
			tableHTML += '        </tr>';
			tableHTML += '    </thead>';
			tableHTML += '    <tbody>';

			var numsArr = new Array();
			var idxArr = new Array();
			for (var i = 0; i < lv1Arr.length; i++) {
				numsArr.push($(lv1Arr[i]).parents('.lv1').find('input[name="lv2"]').length);
				idxArr[i] = 0;
			}

			var len = 1;
			var rowsArr = new Array();
			for (var i = 0; i < numsArr.length; i++) {
				len = len * numsArr[i];

				var tmpnum = 1;
				for (var j = numsArr.length - 1; j > i; j--) {
					tmpnum = tmpnum * numsArr[j];
				}
				rowsArr.push(tmpnum);
			}
			key = 'test';

			for (var i = 0; i < len; i++) {
				tableHTML += '        <tr data-row="' + (i + 1) + '">';

				var name = '';
				var value = '';
				for (var j = 0; j < lv1Arr.length; j++) {
					var n = parseInt(i / rowsArr[j]);
					if (j == 0) {} else if (j == lv1Arr.length - 1) {
						n = idxArr[j];
						if (idxArr[j] + 1 >= numsArr[j]) {
							idxArr[j] = 0;
						} else {
							idxArr[j]++;
						}
					} else {
						var m = parseInt(i / rowsArr[j]);
						n = m % numsArr[j];
					}

					var text = $(lv1Arr[j]).parents('.lv1').find('input[name="lv2"]').eq(n).val();
					var id = $(lv1Arr[j]).parents('.lv1').find('input[name="lv2"]').eq(n).attr('data-id');
					if (j != lv1Arr.length - 1) {
						value += id + ',';
						name += text + ',';
					} else {
						name += text;
						value += id;

					}

					if (i % rowsArr[j] == 0) {
						tableHTML += '<td width="50" rowspan="' + rowsArr[j] + '" data-rc="' + (i + 1) + ',' + (j +
							1) + '">' + text + '</td>';
					}
					//key=$(lv1Arr[j]).val();
					// key=$(lv1Arr[j]).attr('data-id');
					// console.log(key);
				}
				// tableHTML += '<td width="20"><input type="text" name="' + value + '|price" value="' + '"/></td>';
				tableHTML += '<td width="20"><input type="text" name="' + value + '|original_price"  value="' +
					'" /></td>';
				tableHTML += '<td width="20"><input type="text" name="' + value + '|code"  value="' + '" /></td>';
				tableHTML += '<td width="20"><input type="text" name="' + value + '|stock"  value="' + '" /></td>';
				tableHTML += '<td width="20" class="im' + i +
					'"><img src="/Public/Home/images/img_sctp.png" id="cc" data-z="' + i +
					'" height="50" width="50"/></td>';
				tableHTML += '</tr>';
			}
			tableHTML += '</tbody>';
			tableHTML += '</table>';

			$('#lv_table_con').show();
			$('#lv_table').html(tableHTML);

		}

		function save_attr() {
			//生成key
			var iid = $('#iid').val();
			var key = [];
			$('.item-attr input[name=lv1]').each(function(index, ele) {
				key.push($(ele).val());
			});
			//生成值
			var need = [];
			for (j = 0; j < key.length; j++) {
				need[j] = [];
			}
			i = 0;
			$('.item-attr input').each(function(index, ele) {
				if ($(ele).attr('name') == 'lv1' && index != 0) {
					i++;
				} else if (index != 0) {
					need[i].push($(ele).val());
				}
			});


			$.ajax({
				'url': 'index.php?s=/Home/Supplier/save_attr',
				'method': 'post',
				'data': {
					key: JSON.stringify(key),
					'value': JSON.stringify(need),
					'good_id': iid
				},
				'sync': 0,
				'success': function(e) {
					// key=e.data.key;
					// value=e.data.value;
					key = e.url.key;
					value = e.url.value;
					create_attr_id(key, value);
				}
			});
		}

		function create_attr_id(key, value) {
			// console.log(key,value);
			$('.item-attr input[name=lv1]').each(function(index, ele) {
				$(ele).attr('data-id', key[index]);
			});
			$('.item-attr input[name=lv2]').each(function(index, ele) {
				$(ele).attr('data-id', value[index]);
			});
			update_table();
			$('#save_product').show();
		}


	});

	function de() {
		var type_id = $("#pr  option:selected").val();
		$.ajax({
			url: "/index.php?s=/Home/Supplier/type_list.html",
			data: {
				type_id: type_id
			},
			dataType: 'json',
			type: 'post',
			success: function(data) {
				// console.log(data.info);return false;
				var hh = '<option value="">选择二级分类</option>';
				$.each(data.info, function(k, v) {
					hh += '<option value="' + v.id + '">' + v.name + '</option>';
				});
				$('#ar').html(hh);
			}
		})
	}

	$("#uploadImgs").click(function() {
		$("#imgs_file").trigger("click");
	})
	$('#imgs_file').change(function() {
		var pics = $(this)[0].files;

		for (var i = 0; i < pics.length; i++) {
			var formData = new FormData();
			var url = "/index.php?s=/Home/Supplier/uploadPicture/session_id/bnd4ctocfa6j4p58c37clm1et3.html";
			formData.append('download', pics[i]);
			$.ajax({
				url: url,
				type: "post",
				data: formData,
				cache: false,
				contentType: false,
				processData: false,
				success: function(data) {
					if (data.status == 1) {
						var imgs = $('#imgs').val();

						//上传成功
						var id = data.id;
						var path = data.path;

						var img_str = '<div class="upload-files-div"><img class="upload-files" src="' +
							path +
							'" /><span class="upload-file-del" onclick="delThisPic(this)">删除</span></div>';
						$('.imgs_div').append(img_str)

						if (imgs == '') {
							imgs = id;
						} else {
							imgs += ',' + id;
						}
						$('#imgs').val(imgs)
					}
				}
			});
		}
	});

	function delThisPic(that) {
		var index = $('.upload-file-del').index(that);
		var imgs = $('#imgs').val();
		var imgs_arr = imgs.split(',')
		//按某个字符切割字符串成数组
		imgs_arr.splice(index, 1);
		//数组转换字符串
		imgs = imgs_arr.join(',');
		$('#imgs').val(imgs);
		$(that).parent().remove();
	}

	$("body").on('click', '#cc', function() {
		var thisObj = $(this);
		var inputFile = document.createElement("input");
		inputFile.type = "file";
		inputFile.name = "file[]";
		inputFile.multiple = "multiple";
		inputFile.accept = "image/jpeg,image/jpg,image/png";
		inputFile.click();
		var z = $(this).data('z');
		$(inputFile).change(function() {
			var files = inputFile.files;
			for (var i = 0; i < files.length; i++) {
				uploadImg(files[i], thisObj, z);
			}
		});
	});

	function uploadImg(file, thisObj, z) {
		var formData = new FormData();
		formData.append('image', file);
		$.ajax({
			url: "/index.php?s=/Home/Supplier/uploadImg.html",
			type: "post",
			data: formData,
			dataType: "json",
			contentType: false,
			processData: false,
			mimeType: "multipart/form-data",
			success: function(data) {
				if (data.code == 0) {
					// 　　console.log(data.info.imgurl);
					var imgid = data.info.imgid;
					// $("input[name='img']").val(imgid);
					var img = data.info.imgurl;
					$('.im' + z).html('<img src="' + img + '" id="cc" height="30" data-z="' + z +
						'" data-id="' + imgid + '" width="30"/>');

				}
			},
		});
	}



    $(".qd").click(function(){

    	var chk_value =[];
		    $("input[type='checkbox']:checked").each(function(){
		    chk_value.push($(this).val());
	    });

    	
    	// $("input[name='course_id']").val(course_id);
    	var one_type_id=$("#one").val()
    	$("input[name='one_type_id']").val(one_type_id);
    	 var one_type_id=$("#two").val()
    	$("input[name='two_type_id']").val(one_type_id);

    	$.ajax({
    		url:"{:U('Supplier/getCourselist')}",
            data:{course_id:chk_value,category:4},
            dataType:'json',
            type:'post',
            success:function(data){
            	// console.log(data.data);return false;
            	var tt='';
                $.each(data.data,function(k,v){
				tt+='<div class="xbnt-kc">';
				tt+='<div class="xbntk-img">';
				tt+='<img src="'+v.img+'" />';
				tt+='</div>';
				tt+='<div class="xbntk-wz">';
				tt+='<h3>'+v.name+'</h3>';
				tt+='<h4>'+v.category_name+'</h4>';
				tt+='</div>';
				tt+='<div class="xbntk-sc">';
				tt+='<img src="__PUBLIC__/Home/images/icon_sc.png" />';

				tt+='<input type="hidden" name="good_id[]" value="'+v.id+'">';
				tt+='</div>';
				tt+='<div class="divclear"></div>';
				tt+='</div>';
                });
                $('.ctxb-sp').append(tt);
                var len=$('.xbnt-kc').size();
                $("input[name='nm']").val(len);
            }
    	}) 
    	$('.tck-demo').hide();
    })

    $('body').on('click','.xbntk-sc', function(){
    	$(this).parent('.xbnt-kc').remove();
        var len=$('.xbnt-kc').size();
        $("input[name='nm']").val(len);
    })


    //点击搜索的时候
    $("#sub").click(function(){
    	var type_id=$('.er option:selected').val();
    	if(type_id ==''){
    		alert('请选择二级分类');return false;
    	}
    	// alert(type_id);return false;
    	// var name=$("input[name='name']").val();
    	var name=$("#namm").val();
    	$.ajax({
            url:"{:U('Supplier/getCourse')}",
            data:{type_id:type_id,name:name},
            dataType:'json',
            type:'post',
            success:function(data){
            	// console.log(data);return false;
            	var hh='';
                $.each(data.data,function(k,v){
                hh+='<div class="tkbfi-box">';
				hh+='<div class="tkbfib-pic">';
				hh+='<img src="'+v.img+'" />';
				hh+='</div>';
				hh+='<div class="tkbfib-bt">'+v.name+'</div>'
				hh+='<input type="checkbox" class="tkbfib-an" name="course" value="'+v.id+'">'
				hh+='</div>';
                });
            	$('.tkbf-img').html(hh);
        	    $("div.holder").jPages({
                    containerID : "itemContainer",
                    perPage: 8
                });
            }
        })
    })
        //选择一级分类的时候，二级分类变动
	function dem(){
        var pid=$('.yi option:selected').val();
        $.ajax({
            url:"{:U('Supplier/getChildTypes')}",
            data:{pid:pid},
            dataType:'json',
            type:'post',
            success:function(data){
                var hh='';
                $.each(data.data,function(k,v){
                 hh +='<option value='+v.id+'>'+v.name+'</option>';
                });
            	$('.er').html(hh);
            }
        })
    }
    	//显示书籍弹出框
    function showCourse()
    {	
        $("#tck-xzkc").show();
        $("div.holder").jPages({
            containerID : "itemContainer",
            perPage: 8
        });
    }
</script>